{
 "nbformat": 4,
 "nbformat_minor": 0,
 "metadata": {
  "colab": {
   "private_outputs": true,
   "provenance": [],
   "authorship_tag": "ABX9TyPw6K7sJaE/ySw8g6ZjwqpY",
   "include_colab_link": true
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3 (ipykernel)",
   "language": "python"
  },
  "language_info": {
   "name": "python"
  }
 },
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-24T10:27:53.032883Z",
     "start_time": "2025-02-24T10:27:47.989676Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from gptpdf import parse_pdf\n",
    "api_key = 'sk-bhquktorrkboffmthsjjzzkuysibcvphybvyioipzhnfqxcx'\n",
    "content, image_paths = parse_pdf(\"demo.pdf\", api_key=api_key, base_url=\"https://api.siliconflow.cn/v1/\", model='Qwen/Qwen2.5-7B-Instruct')\n",
    "print(content)"
   ],
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2025-02-24 18:27:47,992 - INFO - parse page: 0\n",
      "2025-02-24 18:27:48,556 - INFO - parse page: 1\n",
      "2025-02-24 18:27:49,066 - INFO - parse page: 2\n",
      "2025-02-24 18:27:49,573 - INFO - parse page: 3\n",
      "2025-02-24 18:27:50,017 - INFO - prompt is not provided, using default prompt.\n",
      "2025-02-24 18:27:50,018 - INFO - rect_prompt is not provided, using default prompt.\n",
      "2025-02-24 18:27:50,019 - INFO - role_prompt is not provided, using default prompt.\n",
      "2025-02-24 18:27:50,020 - INFO - gpt parse page: 0\n",
      "2025-02-24 18:27:50,919 - INFO - HTTP Request: POST https://api.siliconflow.cn/v1/chat/completions \"HTTP/1.1 400 Bad Request\"\n",
      "2025-02-24 18:27:50,920 - ERROR - Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 167, in _llm_inference_with_stream\n",
      "    response = client.chat.completions.create(\n",
      "               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_utils\\_utils.py\", line 279, in wrapper\n",
      "    return func(*args, **kwargs)\n",
      "           ^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\resources\\chat\\completions\\completions.py\", line 879, in create\n",
      "    return self._post(\n",
      "           ^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1290, in post\n",
      "    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))\n",
      "                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 967, in request\n",
      "    return self._request(\n",
      "           ^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1071, in _request\n",
      "    raise self._make_status_error_from_response(err.response) from None\n",
      "openai.BadRequestError: Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "2025-02-24 18:27:50,922 - ERROR - LLM(Large Languate Model) error, Please check your key or base_url, or network\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 167, in _llm_inference_with_stream\n",
      "    response = client.chat.completions.create(\n",
      "               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_utils\\_utils.py\", line 279, in wrapper\n",
      "    return func(*args, **kwargs)\n",
      "           ^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\resources\\chat\\completions\\completions.py\", line 879, in create\n",
      "    return self._post(\n",
      "           ^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1290, in post\n",
      "    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))\n",
      "                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 967, in request\n",
      "    return self._request(\n",
      "           ^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1071, in _request\n",
      "    raise self._make_status_error_from_response(err.response) from None\n",
      "openai.BadRequestError: Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "\n",
      "During handling of the above exception, another exception occurred:\n",
      "\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\agent\\agent.py\", line 403, in _llm_and_parse_output\n",
      "    for token in response:\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 184, in _llm_inference_with_stream\n",
      "    raise ValueError('LLM(Large Languate Model) error, Please check your key or base_url, or network')\n",
      "ValueError: LLM(Large Languate Model) error, Please check your key or base_url, or network\n",
      "2025-02-24 18:27:50,924 - INFO - gpt parse page: 1\n",
      "2025-02-24 18:27:51,665 - INFO - HTTP Request: POST https://api.siliconflow.cn/v1/chat/completions \"HTTP/1.1 400 Bad Request\"\n",
      "2025-02-24 18:27:51,666 - ERROR - Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 167, in _llm_inference_with_stream\n",
      "    response = client.chat.completions.create(\n",
      "               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_utils\\_utils.py\", line 279, in wrapper\n",
      "    return func(*args, **kwargs)\n",
      "           ^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\resources\\chat\\completions\\completions.py\", line 879, in create\n",
      "    return self._post(\n",
      "           ^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1290, in post\n",
      "    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))\n",
      "                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 967, in request\n",
      "    return self._request(\n",
      "           ^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1071, in _request\n",
      "    raise self._make_status_error_from_response(err.response) from None\n",
      "openai.BadRequestError: Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "2025-02-24 18:27:51,667 - ERROR - LLM(Large Languate Model) error, Please check your key or base_url, or network\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 167, in _llm_inference_with_stream\n",
      "    response = client.chat.completions.create(\n",
      "               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_utils\\_utils.py\", line 279, in wrapper\n",
      "    return func(*args, **kwargs)\n",
      "           ^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\resources\\chat\\completions\\completions.py\", line 879, in create\n",
      "    return self._post(\n",
      "           ^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1290, in post\n",
      "    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))\n",
      "                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 967, in request\n",
      "    return self._request(\n",
      "           ^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1071, in _request\n",
      "    raise self._make_status_error_from_response(err.response) from None\n",
      "openai.BadRequestError: Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "\n",
      "During handling of the above exception, another exception occurred:\n",
      "\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\agent\\agent.py\", line 403, in _llm_and_parse_output\n",
      "    for token in response:\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 184, in _llm_inference_with_stream\n",
      "    raise ValueError('LLM(Large Languate Model) error, Please check your key or base_url, or network')\n",
      "ValueError: LLM(Large Languate Model) error, Please check your key or base_url, or network\n",
      "2025-02-24 18:27:51,669 - INFO - gpt parse page: 2\n",
      "2025-02-24 18:27:52,383 - INFO - HTTP Request: POST https://api.siliconflow.cn/v1/chat/completions \"HTTP/1.1 400 Bad Request\"\n",
      "2025-02-24 18:27:52,385 - ERROR - Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 167, in _llm_inference_with_stream\n",
      "    response = client.chat.completions.create(\n",
      "               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_utils\\_utils.py\", line 279, in wrapper\n",
      "    return func(*args, **kwargs)\n",
      "           ^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\resources\\chat\\completions\\completions.py\", line 879, in create\n",
      "    return self._post(\n",
      "           ^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1290, in post\n",
      "    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))\n",
      "                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 967, in request\n",
      "    return self._request(\n",
      "           ^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1071, in _request\n",
      "    raise self._make_status_error_from_response(err.response) from None\n",
      "openai.BadRequestError: Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "2025-02-24 18:27:52,386 - ERROR - LLM(Large Languate Model) error, Please check your key or base_url, or network\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 167, in _llm_inference_with_stream\n",
      "    response = client.chat.completions.create(\n",
      "               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_utils\\_utils.py\", line 279, in wrapper\n",
      "    return func(*args, **kwargs)\n",
      "           ^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\resources\\chat\\completions\\completions.py\", line 879, in create\n",
      "    return self._post(\n",
      "           ^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1290, in post\n",
      "    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))\n",
      "                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 967, in request\n",
      "    return self._request(\n",
      "           ^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1071, in _request\n",
      "    raise self._make_status_error_from_response(err.response) from None\n",
      "openai.BadRequestError: Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "\n",
      "During handling of the above exception, another exception occurred:\n",
      "\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\agent\\agent.py\", line 403, in _llm_and_parse_output\n",
      "    for token in response:\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 184, in _llm_inference_with_stream\n",
      "    raise ValueError('LLM(Large Languate Model) error, Please check your key or base_url, or network')\n",
      "ValueError: LLM(Large Languate Model) error, Please check your key or base_url, or network\n",
      "2025-02-24 18:27:52,388 - INFO - gpt parse page: 3\n",
      "2025-02-24 18:27:53,023 - INFO - HTTP Request: POST https://api.siliconflow.cn/v1/chat/completions \"HTTP/1.1 400 Bad Request\"\n",
      "2025-02-24 18:27:53,024 - ERROR - Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 167, in _llm_inference_with_stream\n",
      "    response = client.chat.completions.create(\n",
      "               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_utils\\_utils.py\", line 279, in wrapper\n",
      "    return func(*args, **kwargs)\n",
      "           ^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\resources\\chat\\completions\\completions.py\", line 879, in create\n",
      "    return self._post(\n",
      "           ^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1290, in post\n",
      "    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))\n",
      "                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 967, in request\n",
      "    return self._request(\n",
      "           ^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1071, in _request\n",
      "    raise self._make_status_error_from_response(err.response) from None\n",
      "openai.BadRequestError: Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "2025-02-24 18:27:53,026 - ERROR - LLM(Large Languate Model) error, Please check your key or base_url, or network\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 167, in _llm_inference_with_stream\n",
      "    response = client.chat.completions.create(\n",
      "               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_utils\\_utils.py\", line 279, in wrapper\n",
      "    return func(*args, **kwargs)\n",
      "           ^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\resources\\chat\\completions\\completions.py\", line 879, in create\n",
      "    return self._post(\n",
      "           ^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1290, in post\n",
      "    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))\n",
      "                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 967, in request\n",
      "    return self._request(\n",
      "           ^^^^^^^^^^^^^^\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\openai\\_base_client.py\", line 1071, in _request\n",
      "    raise self._make_status_error_from_response(err.response) from None\n",
      "openai.BadRequestError: Error code: 400 - {'code': 20041, 'message': 'The model is not a VLM (Vision Language Model). Please use text-only prompts.', 'data': None}\n",
      "\n",
      "During handling of the above exception, another exception occurred:\n",
      "\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\agent\\agent.py\", line 403, in _llm_and_parse_output\n",
      "    for token in response:\n",
      "  File \"C:\\ProgramData\\miniconda3\\envs\\searxng\\Lib\\site-packages\\GeneralAgent\\skills\\openai_model.py\", line 184, in _llm_inference_with_stream\n",
      "    raise ValueError('LLM(Large Languate Model) error, Please check your key or base_url, or network')\n",
      "ValueError: LLM(Large Languate Model) error, Please check your key or base_url, or network\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LLM(Large Languate Model) error, Please check your key or base_url, or network\n",
      "\n",
      "\n",
      "LLM(Large Languate Model) error, Please check your key or base_url, or network\n",
      "\n",
      "\n",
      "LLM(Large Languate Model) error, Please check your key or base_url, or network\n",
      "\n",
      "\n",
      "LLM(Large Languate Model) error, Please check your key or base_url, or network\n",
      "\n"
     ]
    }
   ],
   "execution_count": 11
  }
 ]
}
